<template>
  <div class="focus">
    <myheader title="我的关注">
      <span
        slot="left"
        class="iconfont iconjiantou2"
        @click="$router.back()"
      ></span>
      <router-link
        class="van-icon van-icon-wap-home-o"
        to="/index"
        slot="right"
      >
      </router-link>
    </myheader>
    <div class="list">
      <div class="box" v-for="(v, i) in arr" :key="i">
        <img :src="v.head_img" />
        <div class="center">
          <p>{{ v.nickname }}</p>
          <span>{{ v.create_date | date_dayformat }}</span>
        </div>
        <span @click="cancelfollow(v.id, i)">取消关注</span>
      </div>
    </div>
  </div>
</template>

<script>
import myheader from "@/components/hmheader.vue";
import { getuserfollows, userunfollows } from "@/apis/user.js";
import axios from "@/utils/myaxios.js";
import { date_dayformat } from "@/utils/myfilters.js";
export default {
  components: {
    myheader,
  },
  async mounted() {
    let res = await getuserfollows();
    this.arr = res.data.data.map((v) => {
      v.head_img = axios.defaults.baseURL + v.head_img;
      return v;
    });
  },
  data() {
    return {
      arr: [],
    };
  },
  filters: {
    date_dayformat,
  },
  methods: {
    async cancelfollow(id, i) {
      let res = await userunfollows(id);
      this.$toast.success(res.data.message);
      //取消关注后刷新页面内(删除每各索引的数据)
      this.arr.splice(i, 1);
    },
  },
};
</script>

<style lang="less" scoped>

.list {
  .box {
    display: flex;
    padding: 25px 10px;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ccc;
    > img {
      display: block;
      width: 50/360 * 100vw;
      height: 50/360 * 100vw;
      border-radius: 50%;
      padding: 0 10px;
    }
    > .center {
      flex: 1;
      > p {
        line-height: 30px;
        font-size: 14px;
      }
      > span {
        font-size: 12px;
        color: #999;
      }
    }
    > span {
      height: 30px;
      background-color: #eee;
      font-size: 13px;
      border-radius: 30px;
      line-height: 30px;
      padding: 0px 15px;
    }
  }
}
</style>